if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_KhachHang_KhachHangMuaHang_GetByMaKhuVuc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_KhachHang_KhachHangMuaHang_GetByMaKhuVuc]
GO

CREATE PROCEDURE [sp_KhachHang_KhachHangMuaHang_GetByMaKhuVuc]
		@Ma_khu_vuc					int
AS
	SELECT	A.ID,
			A.Ten,
			A.Ma_khu_vuc,
			A.Ma_nhom_khach_hang,
			A.Dia_chi,
			A.Tel,
			A.Fax,
			A.Email,
			A.So_tai_khoan,
			A.Ngan_hang,
			A.Ma_so_thue,
			A.Ghi_chu,
			A.Ngay_cap_nhat_cuoi,
			B.Ten AS 'Ten_nhom_khach_hang',
			C.ID AS 'Ma_loai_khach_hang',
			C.Ten AS 'Ten_loai_khach_hang'
	FROM KhachHang AS A
	INNER JOIN NhomKhachHang AS B ON A.Ma_nhom_khach_hang = B.ID
	INNER JOIN LoaiKhachHang AS C ON B.Ma_loai_khach_hang = C.ID
	WHERE A.Ma_khu_vuc = @Ma_khu_vuc
	AND C.ID = 0